﻿/// ****************************************************************************
/// Author:	        Robin Zhu
/// Create Date:	2012-4-15
/// Purpose: 		扩展成员身份类
/// ****************************************************************************
/// Modify By		Date			Remark
/// Robin           2012-6-1        增加对UserName修改的接口
/// Robin           2013-5-24       增加IsStaff属性
/// ****************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace RB.Web.Security
{
    public class VarMembershipUser : MembershipUser
    {
        public VarMembershipUser()
            : base()
        {
            _userName = base.UserName;
        }

        public VarMembershipUser(
                string providerName,
                string name,
                Object providerUserKey,
                string email,
                string passwordQuestion,
                string comment,
                bool isApproved,
                bool isLockedOut,
                DateTime creationDate,
                DateTime lastLoginDate,
                DateTime lastActivityDate,
                DateTime lastPasswordChangedDate,
                DateTime lastLockoutDate,
                string firstName,
                string lastName,
                bool isStaff
            )
            : base(providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut,
                creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
        {
            _userName = name;
            FirstName = firstName;
            LastName = lastName;
            IsStaff = isStaff;
        }

        public VarMembershipUser(
                string providerName,
                UserAccount userAccount)
            : base(providerName, userAccount.UserName, userAccount.Id, userAccount.Email, 
            userAccount.PasswordQuestion, userAccount.Comment, userAccount.IsApproved, userAccount.IsLockedOut,
            userAccount.CreateTime ?? DateTime.Now, 
            userAccount.LastLoginDate ?? DateTime.Now, 
            userAccount.LastActivityDate ?? DateTime.Now, 
            userAccount.LastPasswordChangedDate ?? DateTime.Now, 
            userAccount.LastLockoutDate ?? DateTime.Now)
        {
            _userName = userAccount.UserName;
            FirstName = userAccount.FirstName;
            LastName = userAccount.LastName;
            IsStaff = userAccount.IsStaff;
        }

        public string FirstName
        {
            get;
            set;
        }

        public string LastName
        {
            get;
            set;
        }

        public bool IsStaff
        {
            get;
            set;
        }

        private string _userName;
        /// <summary>
        /// 重写UserName属性，以便能对其赋值
        /// </summary>
        public override string UserName { get { return _userName; } }
        /// <summary>
        /// 设置UserName
        /// </summary>
        /// <param name="name">新的UserName值</param>
        public void SetUserName(string name) { _userName = name; }

    }
}
